package com.hl.sfzy.controller;

import com.github.pagehelper.PageInfo;
import com.hl.sfzy.entity.CourseReply;
import com.hl.sfzy.entity.CourseTalk;
import com.hl.sfzy.service.CourseReplyService;
import com.hl.sfzy.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/courseReply")
public class CourseReplyController {
    @Autowired
    private CourseReplyService courseReplyService;

    @PostMapping("/add")
    public R add(@RequestBody CourseReply courseReply){
        int num = courseReplyService.add(courseReply);
        if (num != 0){
            return R.ok("添加成功");
        }else {
            return R.fail("添加失败");
        }
    }
    @DeleteMapping("/{id}")
    public R removeByPrimaryKey(@PathVariable("id") Long id){
        int num = courseReplyService.removeByPrimaryKey(id);
        if (num!= 0){
            return R.ok("删除成功");
        }else {
            return R.fail("删除失败");
        }
    }
    @DeleteMapping("/removeBatch")
    public R removeBatch(@RequestBody List<Long> ids){
        int num = courseReplyService.removeBatch(ids);
        if (num!= 0){
            return R.ok("删除成功");
        }else {
            return R.fail("删除失败");
        }
    }
    @PutMapping("/edit")
    public R editByPrimaryKey(@RequestBody CourseReply courseReply){
        int num = courseReplyService.editByPrimaryKey(courseReply);
        if (num!= 0){
            return R.ok("修改成功");
        }else {
            return R.fail("修改失败");
        }
    }
    @GetMapping("/findByPrimaryKey")
    public R findByPrimaryKey(Long id){
        CourseReply courseReply = courseReplyService.findByPrimaryKey(id);
        return R.ok(courseReply);
    }
    @GetMapping("/find")
    public R find(@RequestParam(required = false) int pageNum,
                  @RequestParam(required = false) int pageSize){
        List<CourseReply> list = courseReplyService.find(pageNum, pageSize);
        return R.ok(list);
    }
    @GetMapping("/findByPage")
    public R findByPage(@RequestParam(required = false,defaultValue = "1") int pageNum,
                        @RequestParam(required = false,defaultValue = "3") int pageSize,
                        CourseReply courseReply){
        PageInfo<CourseReply> pageInfo = courseReplyService.findByPage(pageNum, pageSize, courseReply);
        return R.ok(pageInfo);
    }
}
